<template>
  <div id="type-writer">
    {{newText}}
  </div>
</template>
<script>
export default {
  name: 'typeWriterCom',
  props: {
    text:String,
    step:{
      type:Number,
      default:250
      }
  },
  data () {
    return {
        oldText:this.text,
        newText:""
    }
  },
  computed: {},
  methods: {
    typewriter(){
        let text = this.oldText
        let i = 0
        let time = setInterval(()=>{
            if(text.length>this.newText.length){
                this.newText += text[i++]
            }else{
                clearInterval(time)
            }
        },this.step)
    }
  },
  created () {
  },
  mounted () {
    this.typewriter(this.oldText)
  },
}
</script>
<style lang="scss" scoped>

</style>
